package com.xiaoshuidi.cloud.module.report.xxljob;

import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.framework.tenant.core.aop.TenantIgnore;
import com.xiaoshuidi.cloud.module.report.service.ajreport.ReportContractRoomDepositService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 租赁押金报表定时
 */
@Component
@Slf4j
public class ReportContractRoomDepositJob {


    @Resource
    private ReportContractRoomDepositService reportContractRoomDepositService;


    @XxlJob("reportContractRoomDepositJob")
    @TenantIgnore
    public void execute() {
        String type = XxlJobHelper.getJobParam();
        if (StrUtil.isNotBlank(type) &&  "all".equals(type)) {
            //全量处理
            reportContractRoomDepositService.insertBathByTime(null, null);
            reportContractRoomDepositService.dataProcessing();
        } else {
            //增量处理
            LocalDateTime start = LocalDate.now().minusDays(2).atStartOfDay();
            LocalDateTime end = LocalDate.now().atStartOfDay().minusSeconds(1);
            reportContractRoomDepositService.dataProcessingByTime(start, end);
        }

    }
}
